//------------Sonic CD Stage Select Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 1: TYPE_STAGESELECT


sub ObjectMain
	switch Object.State
	case 0
		LoadPalette("StageSelect.act",0,0,0,256)
		TempValue0=256
		TempValue0-=Screen.CenterX
		Screen.XOffset=TempValue0
		Object.Value0=384
		object.value6=-8
		Object.State++
		SetScreenFade(0,0,0,255)
		PlayMusic(0)
		break
	case 1
		if Object.Value0>0
			SetScreenFade(0,0,0,Object.Value0)
			Object.Value0-=8
		else
			object.value6=-8
			Object.State++
		endif
		break
	case 2		
		if object.value6<-8
			object.value6++
		endif
		if KeyPress.Up==1
			Object.Value2=0
			Object.Value1-=10
			if Object.Value1<0
				Object.Value1=60
			endif
		else
			if KeyPress.Down==1
				Object.Value2=0
				Object.Value1+=10
				if Object.Value1>60
					Object.Value1=0
				endif
			endif
		endif
		if KeyDown.Up==1
			Object.Value2++
			if Object.Value2==32
				Object.Value2=0
				Object.Value1-=10
				if Object.Value1<0
					Object.Value1=60
				endif
			endif
		else
			if KeyDown.Down==1
				Object.Value2++
				if Object.Value2==32
					Object.Value2=0
					Object.Value1+=10
					if Object.Value1>60
						Object.Value1=0
					endif
				endif
			endif
		endif
		if KeyPress.ButtonB==1
			Object.State=6
		endif
		if TimeAttack.MenuSection==0
			if KeyPress.Start==1
				object.value6=-8
				Object.State=3
			endif
			if KeyPress.ButtonA==1
				object.value6=-8
				Object.State=3
			endif
			if KeyPress.ButtonC==1
				Stage.PlayerListPos++
				if Stage.PlayerListPos>2
					Stage.PlayerListPos=0
				endif
			endif
		else
			if KeyPress.Start==1
				Object.State=5
			endif
			if KeyPress.ButtonA==1
				Object.State=5
			endif
		endif
#platform: Mobile
		TempValue0=Screen.CenterX
		TempValue0-=138
		TempValue1=Screen.CenterX
		TempValue1-=76
		CheckTouchRect(TempValue0,20,TempValue1,72)
		if CheckResult>-1
			KeyDown.Up=1
			Object.Value2++
			if Object.Value2==32
				Object.Value2=0
				Object.Value1--
				if Object.Value1<0
					Object.Value1=69
				endif
			endif
		endif
		CheckTouchRect(TempValue0,162,TempValue1,214)
		if CheckResult>-1
			KeyDown.Down=1
			Object.Value2++
			if Object.Value2==32
				Object.Value2=0
				Object.Value1++
				if Object.Value1>69
					Object.Value1=0
				endif
			endif
		endif
		if Engine.Message==2
			Object.Value3=0
		endif
		TempValue0=Screen.CenterX
		TempValue0+=28
		TempValue1=Screen.CenterX
		TempValue1+=68
		CheckTouchRect(TempValue0,162,TempValue1,214)
		if CheckResult>-1
			Object.Value3=1
		else
			CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
			if CheckResult<0
				if Object.Value3==1
					Object.Value3=0
					PlaySfx(27,0)
					Object.State=6
				endif
			else
				if Object.Value3==1
					Object.Value3=0
				endif
			endif
		endif
		TempValue0+=48
		TempValue1+=48
		CheckTouchRect(TempValue0,162,TempValue1,214)
		if CheckResult>-1
			Object.Value3=2
		else
			CheckTouchRect(0,0,Screen.XSize,Screen.YSize)
			if CheckResult<0
				if Object.Value3==2
					Object.Value3=0
					PlaySfx(27,0)
					Object.State=3
				endif
			else
				if Object.Value3==2
					Object.Value3=0
				endif
			endif
		endif
#endplatform
		break
	case 3
		if object.value6>-28
			object.value6--
		endif
		TempValue2=Object.Value1
		switch TempValue2
		case 0
		case 10
		case 20
		case 30
		case 40
		case 50
		case 60
			TempValue3=TempValue2
			TempValue3+=0
			TempValue4=TempValue2
			TempValue4+=8
			break
		endswitch
		if TimeAttack.MenuSection==0
			if KeyPress.Left==1
				Object.Value2=0
				Object.Value1-=4
				if Object.Value1<TempValue3
					Object.Value1=TempValue4
				endif
			else
				if KeyPress.Right==1
					Object.Value2=0
					Object.Value1+=4
					if Object.Value1>TempValue4
						Object.Value1=TempValue3
					endif
				endif
			endif
			if KeyDown.Left==1
				Object.Value2++
				if Object.Value2==32
					Object.Value2=0
					Object.Value1-=4
					if Object.Value1<TempValue3
						Object.Value1=TempValue4
					endif
				endif
			else
				if KeyDown.Right==1
					Object.Value2++
					if Object.Value2==32
						Object.Value2=0
						Object.Value1+=4
						if Object.Value1>TempValue4
							Object.Value1=TempValue3
						endif
					endif
				endif
			endif
			if KeyPress.ButtonC==1
				Stage.PlayerListPos++
				if Stage.PlayerListPos>2
					Stage.PlayerListPos=0
				endif
			endif
		endif
		if KeyPress.Start==1
			Object.State=4
		endif
		if KeyPress.ButtonA==1
			Object.State=4
		endif
		if KeyPress.ButtonB==1
			Object.State=2
		endif
		break	
	case 4
		if object.value6>-28
			object.value6--
		endif
		TempValue2=Object.Value1
		switch TempValue2
		case 0
		case 10
		case 20
		case 30
		case 40
		case 50
		case 60
		case 4
		case 14
		case 24
		case 34
		case 44
		case 54
		case 64
			TempValue5=TempValue2
			TempValue5+=0
			TempValue6=TempValue2
			TempValue6+=3
			break
		case 8
		case 18
		case 28
		case 38
		case 48
		case 58
		case 68
			TempValue5=TempValue2
			TempValue5+=0
			TempValue6=TempValue2
			TempValue6+=1
			break
		endswitch
		if KeyPress.Left==1
			Object.Value2=0
			Object.Value1-=1
			if Object.Value1<TempValue5
				Object.Value1=TempValue6
			endif
		else
			if KeyPress.Right==1
				Object.Value2=0
				Object.Value1+=1
				if Object.Value1>TempValue6
					Object.Value1=TempValue5
				endif
			endif
		endif
		if KeyDown.Left==1
			Object.Value2++
			if Object.Value2==32
				Object.Value2=0
				Object.Value1-=1
				if Object.Value1<TempValue5
					Object.Value1=TempValue6
				endif
			endif
		else
			if KeyDown.Right==1
				Object.Value2++
				if Object.Value2==32
					Object.Value2=0
					Object.Value1+=1
					if Object.Value1>TempValue6
						Object.Value1=TempValue5
					endif
				endif
			endif
		endif
		if KeyPress.ButtonC==1
			Stage.PlayerListPos++
			if Stage.PlayerListPos>2
				Stage.PlayerListPos=0
			endif
		endif
		if KeyPress.Start==1
			Object.State=5
		endif
		if KeyPress.ButtonA==1
			Object.State=5
		endif
		if KeyPress.ButtonB==1
			Object.State=3
		endif
		break
	case 5
		if object.value6>-28
			object.value6--
		endif
		StopMusic()
		if Object.Value0<288
			Object.Value0+=8
		else
           if Stage.ActiveList==PRESENTATION_STAGE
			Options.GameMode=0
#platform: Mobile
			Player.Lives=3
#endplatform
	   endif
			Stage.ActiveList=REGULAR_STAGE
			Stage.ListPos=Object.Value1
			LoadStage()
		endif
		TempValue0=Object.Value0
		if TempValue0>255
			TempValue0=255
		endif
		SetScreenFade(0,0,0,TempValue0)
		break
	case 6
		if Object.Value0<288
			Object.Value0+=8
		else
			Options.GameMode=0
			Stage.ActiveList=PRESENTATION_STAGE
			Stage.ListPos=1
			LoadStage()
		endif
		TempValue0=Object.Value0
		if TempValue0>255
			TempValue0=255
		endif
		SetScreenFade(0,0,0,TempValue0)
		break
	endswitch
endsub


sub ObjectDraw
	Object.Value4--
	if Object.Value4<-31
		Object.Value4+=32
	endif
	TempValue1=Object.Value4
	TempValue1>>=1
	//TempValue0=0
	//while TempValue0<240
	//	TempValue1=0
	//	while TempValue1<Screen.XSize
	//		DrawSpriteScreenXY(8,TempValue1,TempValue0)
	//		TempValue1+=224
	//	loop
	//	TempValue0+=48
	//loop
	TempValue1=Object.Value1
	TempValue1/=10
	TempValue0=Screen.CenterX
	TempValue0+=25
	TempValue0+=3
	TempValue0-=228
	DrawSpriteScreenXY(0,TempValue0,0) //Palmtree text
	TempValue0+=228	
	TempValue0-=160
	Object.value7=object.value6
	Object.value7+=15
	if TimeAttack.MenuSection==0
		if Object.State<4
			TempValue0+=40
			DrawSpriteScreenXY(15,TempValue0,112) //Zone
			TempValue0-=40
		else
			TempValue0+=40
			DrawSpriteScreenXY(16,TempValue0,112) // Zone Highlight
			TempValue0-=40
		endif
	endif
	if TimeAttack.MenuSection==0
		DrawRect(0,object.value7,200,125,99,97,132,255)
		DrawSpriteScreenXY(47,TempValue0,Object.value7) //Zone text
		Object.value7+=18
		DrawSpriteScreenXY(1,TempValue0,Object.value7) //Palmtree text
		Object.value7+=15
		DrawSpriteScreenXY(2,TempValue0,Object.value7) //Collision text
		Object.value7+=15
		DrawSpriteScreenXY(3,TempValue0,Object.value7) //Tidal text
		Object.value7+=15
		DrawSpriteScreenXY(4,TempValue0,Object.value7) //Quartz text
		Object.value7+=15
		DrawSpriteScreenXY(5,TempValue0,Object.value7) //Wacky text
		Object.value7+=15
		DrawSpriteScreenXY(6,TempValue0,Object.value7) //Stardust text
		Object.value7+=15
		DrawSpriteScreenXY(7,TempValue0,Object.value7) //Metallic text
		//DrawSpriteScreenXY(18,TempValue0,115) //Final Text
		//DrawSpriteScreenXY(11,TempValue0,130)	//Desert Text
	else
		DrawSpriteScreenXY(47,TempValue0,50) //Zone text
		DrawSpriteScreenXY(1,TempValue0,68) //Palmtree text
		DrawSpriteScreenXY(2,TempValue0,83) //Collision text
		DrawSpriteScreenXY(3,TempValue0,98) //Tidal text
		DrawSpriteScreenXY(4,TempValue0,113) //Quartz text
		DrawSpriteScreenXY(5,TempValue0,128) //Wacky text
		DrawSpriteScreenXY(6,TempValue0,143) //Stardust text
		DrawSpriteScreenXY(7,TempValue0,158) //Metallic text
		//DrawSpriteScreenXY(18,TempValue0,173) //Final Text
		//DrawSpriteScreenXY(11,TempValue0,188)	//Desert Text
	endif
	if TimeAttack.MenuSection==0
		if Stage.PlayerListPos==0
			DrawSpriteScreenXY(37,TempValue0,215) //C
			TempValue0+=40
			DrawSpriteScreenXY(34,TempValue0,210) //Highlight Sonic
			TempValue0+=40
			DrawSpriteScreenXY(35,TempValue0,210) //Tails
			TempValue0+=40
			DrawSpriteScreenXY(48,TempValue0,210) //Amy
			TempValue0-=120
		endif
		if Stage.PlayerListPos==1
			DrawSpriteScreenXY(37,TempValue0,215) //C
			TempValue0+=40
			DrawSpriteScreenXY(33,TempValue0,210) //Sonic
			TempValue0+=40
			DrawSpriteScreenXY(36,TempValue0,210) //Highlight Tails
			TempValue0+=40
			DrawSpriteScreenXY(48,TempValue0,210) //Amy
			TempValue0-=120
		endif
		if Stage.PlayerListPos==2
			DrawSpriteScreenXY(37,TempValue0,215) //C
			TempValue0+=40
			DrawSpriteScreenXY(33,TempValue0,210) //Sonic
			TempValue0+=40
			DrawSpriteScreenXY(35,TempValue0,210) //Tails
			TempValue0+=40
			DrawSpriteScreenXY(49,TempValue0,210) //Highlight Amy
			TempValue0-=120
		endif
	endif
	TempValue0+=160
	Object.value7=object.value6
	Object.value7+=15
	switch TempValue1
	case 0
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=18
			DrawSpriteScreenXY(8,TempValue0,Object.value7) //PP Highlight
		else
			DrawSpriteScreenXY(8,TempValue0,68) //PP Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(38,TempValue0,0)  //PP Icon
		TempValue0+=14
		break
	case 1		
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=33
			DrawSpriteScreenXY(9,TempValue0,Object.value7) //CC Highlight
		else
			DrawSpriteScreenXY(9,TempValue0,83) //CC Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(39,TempValue0,0)  //CC Icon
		TempValue0+=14
		break
	case 2
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=48
			DrawSpriteScreenXY(10,TempValue0,Object.value7) //TT Highlight
		else
			DrawSpriteScreenXY(10,TempValue0,98) //TT Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(40,TempValue0,0) //TT Icon
		TempValue0+=14
		break
	case 3
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=63
			DrawSpriteScreenXY(11,TempValue0,Object.value7) //QQ Highlight
		else
			DrawSpriteScreenXY(11,TempValue0,113) //QQ Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(41,TempValue0,0) //QQ Icon
		TempValue0+=14
		break
	case 4
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=78
			DrawSpriteScreenXY(12,TempValue0,Object.value7) //WW Highlight
		else
			DrawSpriteScreenXY(12,TempValue0,128) //WW Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(42,TempValue0,0) //WW Icon
		TempValue0+=14
		break
	case 5
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=93
			DrawSpriteScreenXY(13,TempValue0,Object.value7) //SS Highlight
		else
			DrawSpriteScreenXY(13,TempValue0,143) //SS Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(43,TempValue0,0) //SS Icon
		TempValue0+=14
		break
	case 6
		TempValue0-=160
		if TimeAttack.MenuSection==0
			Object.value7+=108
			DrawSpriteScreenXY(14,TempValue0,Object.value7) //MM Highlight
		else
			DrawSpriteScreenXY(14,TempValue0,158) //MM Highlight
		endif
		TempValue0+=150
		DrawSpriteScreenXY(44,TempValue0,0)  //MM Icon
		TempValue0+=14
		break
	case 7
		if TimeAttack.MenuSection==0
			//DrawSpriteScreenXY(27,TempValue0,115) //FF Highlight
		else
			//DrawSpriteScreenXY(27,TempValue0,173) //FF Highlight
		endif
		break
	case 8
		if TimeAttack.MenuSection==0
			//DrawSpriteScreenXY(20,TempValue0,130) //DD Highlight
		else
			//DrawSpriteScreenXY(20,TempValue0,188) //DD Highlight
		endif
		break//Levels
	endswitch
		TempValue0-=15
		TempValue7+=1
		if TempValue7>16
			TempValue7=-16
		endif
		TempValue7-=16
		DrawSpriteScreenXY(45,TempValue0,TempValue7)
		TempValue0+=118
		DrawSpriteScreenXY(46,TempValue0,TempValue7)
		TempValue0+=10	
		DrawSpriteScreenXY(0,TempValue0,0) //Palmtree text
		TempValue0-=10
		TempValue7+=16
		TempValue0-=118
		TempValue0+=15
		TempValue0=Screen.CenterX
		TempValue0+=25
		TempValue1=Object.Value1
		TempValue1%=10
		TempValue1>>=2
		TempValue1++
		TempValue0-=180
		if TimeAttack.MenuSection==1
			TempValue0-=96
			TempValue0+=160
			TempValue0+=48
		endif
	if TimeAttack.MenuSection==0
		if TempValue1==1
		if Object.State>2
				DrawSpriteScreenXY(20,TempValue0,120)//Highlight Round 1
			else
				DrawSpriteScreenXY(17,TempValue0,120) //Round 1
			endif
		else
			DrawSpriteScreenXY(17,TempValue0,120) //Round 1
		endif
		TempValue0+=60
		if TempValue1==2
			DrawSpriteScreenXY(21,TempValue0,120)//Highlight Round 2
		else
			DrawSpriteScreenXY(18,TempValue0,120) //Round 2
		endif
		TempValue0+=60
		if TempValue1==3
			DrawSpriteScreenXY(22,TempValue0,120)//Highlight Round 3
		else
			DrawSpriteScreenXY(19,TempValue0,120) //Round 3
		endif
		TempValue1=Object.Value1
		TempValue1%=10
		TempValue0-=120
		DrawSpriteScreenXY(23,TempValue0,170) //Present
		TempValue0+=60
		DrawSpriteScreenXY(24,TempValue0,166) //Past
		if TempValue1==8
			TempValue0-=60
			DrawSpriteScreenXY(31,TempValue0,170) //Block Present
			TempValue0+=60
			DrawSpriteScreenXY(32,TempValue0,166) //Block Past
		endif
		if TempValue1==9
			TempValue0-=60
			DrawSpriteScreenXY(31,TempValue0,170) //Block Present
			TempValue0+=60
			DrawSpriteScreenXY(32,TempValue0,166) //Block Past
		endif
		TempValue0+=40
		DrawSpriteScreenXY(25,TempValue0,166) //Good Future
		TempValue0+=40
		DrawSpriteScreenXY(26,TempValue0,169) //Bad Future
		endif
		if Object.State==4
			switch TempValue1
			case 0
			case 4
				TempValue0-=140
				DrawSpriteScreenXY(27,TempValue0,190) //Highlight Present
				break
			case 1
			case 5
				TempValue0-=80
				DrawSpriteScreenXY(28,TempValue0,190) //Highlight Past
				break
			case 2
			case 6
			case 8
				TempValue0-=40
				DrawSpriteScreenXY(29,TempValue0,190) //Highlight Good Future
				break
			case 3
			case 7
			case 9
				DrawSpriteScreenXY(29,TempValue0,190) //Highlight Bad Future
				break
			endswitch
		endif
#platform: Mobile
		TempValue0-=96
		if KeyDown.Up==1
			DrawSpriteScreenXY(18,TempValue0,48)
		else
			DrawSpriteScreenXY(17,TempValue0,48)
		endif
		if KeyDown.Down==1
			DrawSpriteScreenXY(20,TempValue0,192)
		else
			DrawSpriteScreenXY(19,TempValue0,192)
		endif
		TempValue0+=160
		if Object.Value3==1
			DrawSpriteScreenXY(24,TempValue0,192)
		else
			DrawSpriteScreenXY(23,TempValue0,192)
		endif
		TempValue0+=48
		if Object.Value3==2
			DrawSpriteScreenXY(22,TempValue0,192)
		else
			DrawSpriteScreenXY(21,TempValue0,192)
		endif
#endplatform
	endif
endsub


sub ObjectStartup
	SetMusicTrack("StageSelect.ogg",0,1)
	if Stage.ListPos==3
		TimeAttack.MenuSection=0
	else
		TimeAttack.MenuSection=1
	endif
	LoadSpriteSheet("Secrets/StageSelect.gif")
	SpriteFrame(-13,0,231,288,294,0) 		//BackGround
	SpriteFrame(0,0,104,10,1,1)		//Palmtree Panic 1
	SpriteFrame(0,0,107,10,1,23)	//Collision Chaos 2
	SpriteFrame(0,0,94,10,1,34)		//Tidal Tempest 3
	SpriteFrame(0,0,118,10,109,1)	//Quartz Quadrant 4
	SpriteFrame(0,0,120,10,109,12)	//Wacky Workbench 5
	SpriteFrame(0,0,131,10,109,23)	//Stardust Speedway 6
	SpriteFrame(0,0,119,10,109,34)	//Metallic Madness 7
	SpriteFrame(0,0,104,10,1,56)	//Highlight Palmtree Panic 8
	SpriteFrame(0,0,107,10,1,78)	//Highlight Collision Chaos 9
	SpriteFrame(0,0,94,10,1,89)		//Highlight Tidal Tempest 10
	SpriteFrame(0,0,118,10,109,56)	//Highlight Quartz Quadrant 11
	SpriteFrame(0,0,120,10,109,67)	//Highlight Wacky Workbench 12
	SpriteFrame(0,0,131,10,109,78)	//Highlight Stardust Speedway 13
	SpriteFrame(0,0,119,10,109,89)	//Highlight Metallic Madness 14
	SpriteFrame(0,0,48,16,148,111) 	//Zone 15
	SpriteFrame(0,0,48,16,148,128)	// Highlight Zone 16
	SpriteFrame(0,0,48,48,1,111) 	//Round 1 17
	SpriteFrame(0,0,48,48,50,111)	//Round 2 18
	SpriteFrame(0,0,48,48,99,111)	//Round 3 19
	SpriteFrame(0,0,48,48,1,160)	//Highlight Round 1 20
	SpriteFrame(0,0,48,48,50,160)	//Highlight Round 2 21
	SpriteFrame(0,0,48,48,99,160)	//Highlight Round 3 22
	SpriteFrame(0,0,51,36,103,213)	// Present 23
	SpriteFrame(0,0,32,40,1,209)	// Past 24
	SpriteFrame(0,0,32,40,35,209)	// G.Future 25
	SpriteFrame(0,0,32,37,69,212)	// B.Future 26
	SpriteFrame(0,0,51,16,103,291)	//Highlight Present 27
	SpriteFrame(0,0,32,16,1,291)	//Highlight Past 28
	SpriteFrame(0,0,32,16,35,291)	//Highlight G.Future 29
	SpriteFrame(0,0,32,16,69,291)	//Highlight B.Future 30
	SpriteFrame(0,0,51,36,103,251)	//Block Present 31
	SpriteFrame(0,0,32,40,1,250)	//Block Past 32
	SpriteFrame(0,0,20,28,148,145)	//Sonic 33
	SpriteFrame(0,0,20,28,169,145)	//Highlight Sonic 34
	SpriteFrame(0,0,20,28,148,174)	//Tails 35
	SpriteFrame(0,0,20,28,169,174)	//Highlight Tails 36
	SpriteFrame(0,0,16,20,190,145)	//C Button 37
	SpriteFrame(0,0,128,288,0,345)	//PP Icon 38
	SpriteFrame(0,0,128,288,128,345)//CC Icon 39
	SpriteFrame(0,0,128,288,256,345)//TT Icon 40
	SpriteFrame(0,0,128,288,384,345)//QQ Icon 41
	SpriteFrame(0,0,128,288,0,633)	//WW Icon 42
	SpriteFrame(0,0,128,288,128,633)//SS Icon 43
	SpriteFrame(0,0,128,288,256,633)//MM Icon 44
	SpriteFrame(0,0,12,288,282,0)	//BackGround 45
	SpriteFrame(-11,0,12,320,269,0) //BackGround2 46
	SpriteFrame(0,0,48,16,198,128) //Completed Save File "Zone" text 47
    SpriteFrame(0,0,20,28,190,174)  //Amy 48
    SpriteFrame(0,0,20,28,211,174)  //Highlight Amy 49
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
